import pandas as pd
from cartoframes.viz import Map, Layer
seattle_collisions = pd.read_csv('data/seattle_collisions.csv')
from cartoframes.viz.widgets import formula_widget, category_widget
Map(
Layer(
seattle_collisions,
widgets=[
formula_widget(
'pedcount',
'sum',
title='Pedestrians Involved'
),
formula_widget(
'pedcylcount',
'sum',
title='Cyclists Involved'
),
category_widget(
'collisiontype',
title='Collision Type'
)
]
)
)
Layer structure:
Layer(
source=...,
style=...,
legend=...,
widgets=...
)
source can be a DataFrame, GeoDataFrame or CartoFrames' Dataset (table or query).style takes a CartoVL styling expressionpopup can be a Popup object, or a dict with hover and/or click as keyslegend can be a Legend object, or just a simple dictionarywidgets takes list of Widget objectsMaps allow you to add several layers, select the basemap, set a viewport, and others.
from cartoframes.viz import Widget, basemaps
df = pd.read_csv('data/maxhi_20190717_72.csv')
Map ([
Layer(
df,
'''
color: ramp(linear($value,globalMIN($value),globalMAX($value)),[turquoise, yellow, red])
filter: animation(linear($value,globalMIN($value),globalMAX($value)), 20, fade(0.1, hold))
strokeWidth: 0
width: 4
''',
legend={
'type':'color-continuous-polygon',
'title': 'Max Heat Index for July 20, 2019',
'description': 'Degrees (°F)',
'footer': 'Issued: 7/17/19 | Source: NOAA Weather Predicition Center'
},
widgets=[
Widget(
'formula',
value='viewportMAX($value)',
title='Max Degrees (°F)',
),
Widget('time-series', value='value', title='Animation by Temperature'),
],
)
],
basemap=basemaps.darkmatter,
show_info=True,
viewport={'zoom': 2.5, 'lat': 37.572586, 'lng': -110.638529},
)